//
//  ZCDataFormat.m
//  ZCLightSDK
//
//  Created by qply on 2020/8/27.
//  Copyright © 2020 Vanney. All rights reserved.
//

#import "ZCFunDataFormat.h"
#import <CommonCrypto/CommonDigest.h>
#import <ImageIO/ImageIO.h>
#import <sys/utsname.h>
#import <sys/sysctl.h>
#include <mach/mach.h>

#import "YZYSDKManagerHeader.h"

@implementation ZCFunDataFormat
    
+ (BOOL)isBlankDictionary:(NSDictionary *)dic {
    if (!dic) {
        return YES;
        
    }
    if ([dic isKindOfClass:[NSNull class]]) {
        return YES;
        
    }
    if (![dic isKindOfClass:[NSDictionary class]]) {
        return YES;
        
    }
    if (!dic.count) {
        return YES;
        
    }
    if (dic == nil) {
        return YES;
        
    }
    if (dic == NULL) {
        return YES;
        
    }
    return NO;
 
}
    
+ (BOOL)isBlankArr:(NSArray *)arr {
    if (!arr) {
        return YES;
        
    }
    if ([arr isKindOfClass:[NSNull class]]) {
        return YES;
        
    }
    if (![arr isKindOfClass:[NSArray class]]) {
        return YES;
        
    }
    if (!arr.count) {
        return YES;
        
    }
    if (arr == nil) {
        return YES;
        
    }
    if (arr == NULL) {
        return YES;
        
    }
    return NO;
}



+ (BOOL)isBlankString:(NSString *)aStr {
    if ( !aStr ) {
        return YES;        
    }
    if ([aStr isKindOfClass:[NSNull class]]) {
        return YES;
        
    }
    if (!aStr.length) {
        return YES;
        
    }
    if (aStr == nil) {
        return YES;
        
    }
    if (aStr == NULL) {
        return YES;
        
    }
    if ([aStr isEqualToString:@"NULL"]) {
        return YES;        
    }
    if ([aStr isEqualToString:@"(null)"]) {
        return YES;
    }
    NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *trimmedStr = [aStr stringByTrimmingCharactersInSet:set];
    if (!trimmedStr.length) {
        return YES;
        
    }
    return NO;
    
}

+ (BOOL)isBlankNumber:(NSNumber *)aNum {
    if (!aNum) {
        return YES;
    }
    if ([aNum isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if (aNum == nil) {
        return YES;
    }
    if (aNum == NULL) {
        return YES;
    }
    return NO;
}
    
+ (BOOL)isBangsScreen {
    BOOL isBangsScreen = NO;
    if (@available(iOS 11.0, *)) {
        UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
        isBangsScreen = window.safeAreaInsets.bottom > 0;
    }
    return isBangsScreen;
}
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        return nil;
    }
    return dic;
}
+ (NSArray *)arrayWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSArray *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                   options:NSJSONReadingMutableContainers
                                                     error:&err];
    if(err) {
        return nil;
    }
    return dic;
}
+(NSString *)urlEncodeStr:(NSString *)input {
    NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";
    NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
    NSString *upSign = [input stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
    return upSign;
}
+(BOOL)isHasChineseChar:(NSString *)string {
    
    BOOL bool_value = NO;
    for (int i=0; i<string.length; i++) {
        NSRange range =NSMakeRange(i, 1);
        NSString * strFromSubStr=[string substringWithRange:range];
        const char * cStringFromstr=[strFromSubStr UTF8String];
        if (strlen(cStringFromstr)==3) {
            //有汉字
            bool_value = YES;
        }
    }
    return bool_value;
}

+ (NSString *)GetQPGameID {
    if (YZY_IS_APPLE) {
        return YZY_QPGameID;
    } else {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"QPJHPLIST" ofType:@"plist"];
        NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
        NSString *game_id = [NSString stringWithFormat:@"%@",data[@"game_id"]];
        if ([self isBlankString:game_id]) {
            return @"";
        } else {
            return game_id;
        }
    }
}

+ (NSString *)GetPlatformGameID {
    if (YZY_IS_APPLE) {
        return YZY_PlatformGameID;
    } else {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"YZYPLIST" ofType:@"plist"];
        NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
        NSString *game_id = [NSString stringWithFormat:@"%@",data[@"SDK_GAME_ID"]];
        if ([self isBlankString:game_id]) {
            return @"";
        } else {
            return game_id;
        }
    }
}

+ (NSString *)GetLOGIN_APP_ID {
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"YZYPLIST" ofType:@"plist"];
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    NSString *LOGIN_APP_ID = [NSString stringWithFormat:@"%@",data[@"LOGIN_APP_ID"]];
    if ([self isBlankString:LOGIN_APP_ID]) {
        return @"";
    } else {
        return LOGIN_APP_ID;
    }
}

+ (NSString *)GetChanneNo {
    if (YZY_IS_APPLE) {
        return @"qipaios";
    } else {
        return @"qipasignios";
    }
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"YZYPLIST" ofType:@"plist"];
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    NSString *channeNo = [NSString stringWithFormat:@"%@",data[@"channel"]];
    if ([self isBlankString:channeNo]) {
        return @"";
    } else {
        return channeNo;
    }
}

+ (BOOL)GetIsLandscape {
    if (YZY_IS_APPLE) {
        if ([YZY_IS_Landscape isEqualToString:@"1"]) {
            return YES;
        } else {
            return NO;
        }
    } else {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"YZYPLIST" ofType:@"plist"];
        NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
        NSString *isLandscape = [NSString stringWithFormat:@"%@",data[@"isLandscape"]];
        if ([isLandscape isEqualToString:@"1"]) {
            return YES;
        } else {
            return NO;
        }
    }
}


+ (NSString *)ZCMD5GetRandomStr {
    return [NSString stringWithFormat:@"%d",(int)(10000 + (arc4random() % (99999 - 10000 + 1)))];
    
}
+ (NSString *)ZCMD5WithNSString:(NSString *)str {
    const char *cStr = [str UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    
    CC_MD5(cStr, strlen(cStr), digest);
    
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [result appendFormat:@"%02x", digest[i]];
    }
    
    return result;
}
+ (CGSize)getImageSizeWithURL:(id)URL {
    NSURL * url = nil;
    if ([URL isKindOfClass:[NSURL class]]) {
        url = URL;
    }
    if ([URL isKindOfClass:[NSString class]]) {
        url = [NSURL URLWithString:URL];
    }
    if (!URL) {
        return CGSizeZero;
    }
    CGImageSourceRef imageSourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
    CGFloat width = 0, height = 0;
    
    if (imageSourceRef) {
        
        // 获取图像属性
        CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSourceRef, 0, NULL);
        
        //以下是对手机32位、64位的处理
        if (imageProperties != NULL) {
            
            CFNumberRef widthNumberRef = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
            
#if defined(__LP64__) && __LP64__
            if (widthNumberRef != NULL) {
                CFNumberGetValue(widthNumberRef, kCFNumberFloat64Type, &width);
            }
            
            CFNumberRef heightNumberRef = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
            
            if (heightNumberRef != NULL) {
                CFNumberGetValue(heightNumberRef, kCFNumberFloat64Type, &height);
            }
#else
            if (widthNumberRef != NULL) {
                CFNumberGetValue(widthNumberRef, kCFNumberFloat32Type, &width);
            }
            
            CFNumberRef heightNumberRef = CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
            
            if (heightNumberRef != NULL) {
                CFNumberGetValue(heightNumberRef, kCFNumberFloat32Type, &height);
            }
#endif
            /***************** 此处解决返回图片宽高相反问题 *****************/
            // 图像旋转的方向属性
            NSInteger orientation = [(__bridge NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyOrientation) integerValue];
            CGFloat temp = 0;
            switch (orientation) {  // 如果图像的方向不是正的，则宽高互换
                case UIImageOrientationLeft: // 向左逆时针旋转90度
                case UIImageOrientationRight: // 向右顺时针旋转90度
                case UIImageOrientationLeftMirrored: // 在水平翻转之后向左逆时针旋转90度
                case UIImageOrientationRightMirrored: { // 在水平翻转之后向右顺时针旋转90度
                    temp = width;
                    width = height;
                    height = temp;
                }
                    break;
                default:
                    break;
            }
            /***************** 此处解决返回图片宽高相反问题 *****************/
            
            CFRelease(imageProperties);
        }
        CFRelease(imageSourceRef);
    }
    return CGSizeMake(width, height);
}
+ (NSAttributedString *)attContentText:(NSString *)text {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentLeft;
    paragraphStyle.lineSpacing = 2;
    [paragraphStyle setFirstLineHeadIndent: 15];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0,text.length)];
    return attributedString;
}
+(NSString *)getNowTimeTimestamp {

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;

    [formatter setDateStyle:NSDateFormatterMediumStyle];

    [formatter setTimeStyle:NSDateFormatterShortStyle];

    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];

    [formatter setTimeZone:timeZone];

    NSDate *datenow = [NSDate date];

    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];

    return timeSp;

}
+ (NSString *)getCurrentDeviceModel {
    struct utsname systemInfo;
    uname(&systemInfo);
      
    NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
      
    if ([deviceModel isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone3,3"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([deviceModel isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([deviceModel isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPhone5,3"])    return @"iPhone 5c (GSM)";
    if ([deviceModel isEqualToString:@"iPhone5,4"])    return @"iPhone 5c (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPhone6,1"])    return @"iPhone 5s (GSM)";
    if ([deviceModel isEqualToString:@"iPhone6,2"])    return @"iPhone 5s (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([deviceModel isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([deviceModel isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([deviceModel isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([deviceModel isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    // 日行两款手机型号均为日本独占，可能使用索尼FeliCa支付方案而不是苹果支付
    if ([deviceModel isEqualToString:@"iPhone9,1"])    return @"iPhone 7";
    if ([deviceModel isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus";
    if ([deviceModel isEqualToString:@"iPhone9,3"])    return @"iPhone 7";
    if ([deviceModel isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus";
    if ([deviceModel isEqualToString:@"iPhone10,1"])   return @"iPhone_8";
    if ([deviceModel isEqualToString:@"iPhone10,4"])   return @"iPhone_8";
    if ([deviceModel isEqualToString:@"iPhone10,2"])   return @"iPhone_8_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,5"])   return @"iPhone_8_Plus";
    if ([deviceModel isEqualToString:@"iPhone10,3"])   return @"iPhone X";
    if ([deviceModel isEqualToString:@"iPhone10,6"])   return @"iPhone X";
    if ([deviceModel isEqualToString:@"iPhone11,8"])   return @"iPhone XR";
    if ([deviceModel isEqualToString:@"iPhone11,2"])   return @"iPhone XS";
    if ([deviceModel isEqualToString:@"iPhone11,6"])   return @"iPhone XS Max";
    if ([deviceModel isEqualToString:@"iPhone11,4"])   return @"iPhone XS Max";
    if ([deviceModel isEqualToString:@"iPhone12,1"])   return @"iPhone 11";
    if ([deviceModel isEqualToString:@"iPhone12,3"])   return @"iPhone 11 Pro";
    if ([deviceModel isEqualToString:@"iPhone12,5"])   return @"iPhone 11 Pro Max";
    if ([deviceModel isEqualToString:@"iPhone12,8"])   return @"iPhone SE2";
    if ([deviceModel isEqualToString:@"iPhone13,1"])   return @"iPhone 12 mini";
    if ([deviceModel isEqualToString:@"iPhone13,2"])   return @"iPhone 12";
    if ([deviceModel isEqualToString:@"iPhone13,3"])   return @"iPhone 12 Pro";
    if ([deviceModel isEqualToString:@"iPhone13,4"])   return @"iPhone 12 Pro Max";
    if ([deviceModel isEqualToString:@"iPhone14,4"])   return @"iPhone 13 mini";
    if ([deviceModel isEqualToString:@"iPhone14,5"])   return @"iPhone 13";
    if ([deviceModel isEqualToString:@"iPhone14,2"])   return @"iPhone 13 Pro";
    if ([deviceModel isEqualToString:@"iPhone14,3"])   return @"iPhone 13 Pro Max";
    if ([deviceModel isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
    if ([deviceModel isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
    if ([deviceModel isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
    if ([deviceModel isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
    if ([deviceModel isEqualToString:@"iPod5,1"])      return @"iPod Touch (5 Gen)";
    if ([deviceModel isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([deviceModel isEqualToString:@"iPad1,2"])      return @"iPad 3G";
    if ([deviceModel isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,2"])      return @"iPad 2";
    if ([deviceModel isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([deviceModel isEqualToString:@"iPad2,4"])      return @"iPad 2";
    if ([deviceModel isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,6"])      return @"iPad Mini";
    if ([deviceModel isEqualToString:@"iPad2,7"])      return @"iPad Mini (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,2"])      return @"iPad 3 (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPad3,3"])      return @"iPad 3";
    if ([deviceModel isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,5"])      return @"iPad 4";
    if ([deviceModel isEqualToString:@"iPad3,6"])      return @"iPad 4 (GSM+CDMA)";
    if ([deviceModel isEqualToString:@"iPad4,1"])      return @"iPad Air (WiFi)";
    if ([deviceModel isEqualToString:@"iPad4,2"])      return @"iPad Air (Cellular)";
    if ([deviceModel isEqualToString:@"iPad4,4"])      return @"iPad Mini 2 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad4,5"])      return @"iPad Mini 2 (Cellular)";
    if ([deviceModel isEqualToString:@"iPad4,6"])      return @"iPad Mini 2";
    if ([deviceModel isEqualToString:@"iPad4,7"])      return @"iPad Mini 3";
    if ([deviceModel isEqualToString:@"iPad4,8"])      return @"iPad Mini 3";
    if ([deviceModel isEqualToString:@"iPad4,9"])      return @"iPad Mini 3";
    if ([deviceModel isEqualToString:@"iPad5,1"])      return @"iPad Mini 4 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad5,2"])      return @"iPad Mini 4 (LTE)";
    if ([deviceModel isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"iPad6,3"])      return @"iPad Pro 9.7";
    if ([deviceModel isEqualToString:@"iPad6,4"])      return @"iPad Pro 9.7";
    if ([deviceModel isEqualToString:@"iPad6,7"])      return @"iPad Pro 12.9";
    if ([deviceModel isEqualToString:@"iPad6,8"])      return @"iPad Pro 12.9";
    if ([deviceModel isEqualToString:@"iPad6,11"])  return @"iPad 5";
    if ([deviceModel isEqualToString:@"iPad6,12"])  return @"iPad 5";
    if ([deviceModel isEqualToString:@"iPad7,1"])  return @"iPad Pro (12.9-inch) 2nd";
    if ([deviceModel isEqualToString:@"iPad7,2"])  return @"iPad Pro (12.9-inch) 2nd";
    if ([deviceModel isEqualToString:@"iPad7,3"])  return @"iPad Pro (10.5-inch)";
    if ([deviceModel isEqualToString:@"iPad7,4"])  return @"iPad Pro (10.5-inch)";
    if ([deviceModel isEqualToString:@"iPad7,5"])  return @"iPad 6";
    if ([deviceModel isEqualToString:@"iPad7,6"])  return @"iPad 6";
    if ([deviceModel isEqualToString:@"iPad7,11"])  return @"iPad 7";
    if ([deviceModel isEqualToString:@"iPad7,12"])  return @"iPad 7";
    if ([deviceModel isEqualToString:@"iPad8,1"])  return @"iPad Pro (11-inch) ";
    if ([deviceModel isEqualToString:@"iPad8,2"])  return @"iPad Pro (11-inch) ";
    if ([deviceModel isEqualToString:@"iPad8,3"])  return @"iPad Pro (11-inch) ";
    if ([deviceModel isEqualToString:@"iPad8,4"])  return @"iPad Pro (11-inch) ";
    if ([deviceModel isEqualToString:@"iPad8,5"])  return @"iPad Pro (12.9-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad8,6"])  return @"iPad Pro (12.9-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad8,7"])  return @"iPad Pro (12.9-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad8,8"])  return @"iPad Pro (12.9-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad8,9"])  return @"iPad Pro (11-inch) 2nd";
    if ([deviceModel isEqualToString:@"iPad8,10"])  return @"iPad Pro (11-inch) 2nd";
    if ([deviceModel isEqualToString:@"iPad8,11"])  return @"iPad Pro (12.9-inch) 4th";
    if ([deviceModel isEqualToString:@"iPad8,12"])  return @"iPad Pro (12.9-inch) 4th";
    if ([deviceModel isEqualToString:@"iPad11,1"])  return @"iPad mini 5";
    if ([deviceModel isEqualToString:@"iPad11,2"])  return @"iPad mini 5";
    if ([deviceModel isEqualToString:@"iPad11,3"])  return @"iPad Air 3";
    if ([deviceModel isEqualToString:@"iPad11,4"])  return @"iPad Air 3";
    if ([deviceModel isEqualToString:@"iPad11,6"])  return @"iPad 8";
    if ([deviceModel isEqualToString:@"iPad11,7"])  return @"iPad 8";
    if ([deviceModel isEqualToString:@"iPad13,1"])  return @"iPad Air 4";
    if ([deviceModel isEqualToString:@"iPad13,2"])  return @"iPad Air 4";
    if ([deviceModel isEqualToString:@"iPad13,4"])  return @"iPad Pro (11-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad13,5"])  return @"iPad Pro (11-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad13,6"])  return @"iPad Pro (11-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad13,7"])  return @"iPad Pro (11-inch) 3rd";
    if ([deviceModel isEqualToString:@"iPad13,8"])  return @"iPad Pro (12.9-inch) 5th";
    if ([deviceModel isEqualToString:@"iPad13,9"])  return @"iPad Pro (12.9-inch) 5th";
    if ([deviceModel isEqualToString:@"iPad13,10"])  return @"iPad Pro (12.9-inch) 5th";
    if ([deviceModel isEqualToString:@"iPad13,11"])  return @"iPad Pro (12.9-inch) 5th";
    if ([deviceModel isEqualToString:@"iPad14,1"])  return @"iPad mini 6";
    if ([deviceModel isEqualToString:@"iPad14,2"])  return @"iPad mini 6";
    
    if ([deviceModel isEqualToString:@"AppleTV2,1"])      return @"Apple TV 2";
    if ([deviceModel isEqualToString:@"AppleTV3,1"])      return @"Apple TV 3";
    if ([deviceModel isEqualToString:@"AppleTV3,2"])      return @"Apple TV 3";
    if ([deviceModel isEqualToString:@"AppleTV5,3"])      return @"Apple TV 4";

    if ([deviceModel isEqualToString:@"i386"])         return @"Simulator";
    if ([deviceModel isEqualToString:@"x86_64"])       return @"Simulator";
    return deviceModel;
}

//系统版本
+ (NSString *)getDeviceSystemVersion {
    return [[UIDevice currentDevice] systemVersion];
}
+ (NSString *)deviceCPUType {
    host_basic_info_data_t hostInfo;
    mach_msg_type_number_t infoCount;
    
    infoCount = HOST_BASIC_INFO_COUNT;
    host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
    
    switch (hostInfo.cpu_type) {
        case CPU_TYPE_ARM:
            return @"arm";
            break;
            
        case CPU_TYPE_ARM64:
            return @"arm64";
            break;
            
        case CPU_TYPE_X86:
            return @"x86";
            break;
            
        case CPU_TYPE_X86_64:
            return @"x86_64";
            break;
            
        default:
            return @"unkown";
            break;
    }
}
+ (NSString *)deviceIsJailbreak{
    static NSString *isjbroken = @"legal";
    if (isjbroken) {
        return @"legal";
    }
    @try {
        NSArray *paths = [NSArray arrayWithObjects:
                          @"/User/Applications/",
                          @"/Applications/Cydia.app",
                          @"/Library/MobileSubstrate/MobileSubstrate.dylib",
                          @"/bin/bash",
                          @"/usr/sbin/sshd",
                          @"/etc/apt",
                          nil];
        
        for (NSString *one in paths) {
            if ([[NSFileManager defaultManager] fileExistsAtPath:one]) {
                isjbroken = @"Jailbreak";
            }
        }
    } @catch (NSException *exception) {
        NSLog(@"Jailbroken exception:%@",exception);
    }
    
    return isjbroken;
}

+ (NSString *)filterString:(NSString *)string {
    if ([ZCFunDataFormat isBlankString:string]) {
        return @"";
    }
    return string;
}
+ (NSNumber *)filterNumber:(NSNumber *)number {
    if ([ZCFunDataFormat isBlankNumber:number]) {
        return @0;
    }
    return number;
}

@end
